<?php
/*
 * 本控制器用户会长管理
 *
 * */
namespace App\Http\Controllers\Webapi;
use App\Common\ApiData;
use App\Models\V1\MemberModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\V1\PrisidentModel;
use App\Models\V1\ChapterModel;


class PrisidentController extends Controller{

    /**
     * 获得会长信息
     * */
    public function prisident_index(Request $request){

        $userId = $request->input('userId',0);
        $chapterModel   = new ChapterModel();
        $apiData        = new ApiData();
        $chapterId      = $request->input('chapterId');
        $roleType       = $request->input('roleType');

        //获取用户的级别

        $chapterInfo        = $chapterModel->chapter_info($chapterId);
        $city               = $chapterInfo->city;


        $prisidentNum   = 0;    //副会长数量
        $localDrpNum    = 0;    //本地学习官数量
        $otherDrpNum    = 0;    //异地学习官
        $localMemberNum = 0;    //本地会员数量
        $otherMemberNum = 0;    //异地会员数量
        $companyNum     = 0;    //企业会员数量


        if($roleType == 'clo') //以学习官身份登录
        {
            $memberNumber       = $chapterModel->count_member_of_clo($userId);
            $drpNumber          = $chapterModel->count_clo_of_clo($userId);
            $companyNum         = $chapterModel->count_company_of_clo($userId);

            //$companyNum         = $chapterModel->count_chapter_company_of_clo($userId);
        }
        else
        {
            $localMemberNum     = $chapterModel->count_member_of_chapter($chapterId,$city);
            $otherMemberNum     = $chapterModel->count_member_of_chapter($chapterId,-$city);
            $localDrpNum        = $chapterModel->count_clo_of_chapter($chapterId,$city);
            $otherDrpNum        = $chapterModel->count_clo_of_chapter($chapterId,-$city);
            $companyNum         = $chapterModel->count_company_of_chapter($chapterId,0);

            $memberNumber       = $localMemberNum + $otherMemberNum;
            $drpNumber          = $localDrpNum + $otherDrpNum;

            /*if($userChapterInfo->role == 4) //如果是发起人
            {
                $prisidentNum       = $chapterModel->count_prisident($chapterId,'F',0);
            }*/
        }


        return $apiData->set_data('prisidentNumber',$prisidentNum)
            ->set_data('localDrpNum',$localDrpNum)
            ->set_data('otherDrpNum',$otherDrpNum)
            ->set_data('localMemberNum',$localMemberNum)
            ->set_data('otherMemberNum',$otherMemberNum)
            ->set_data('memberNum',$memberNumber)
            ->set_data('drpNum',$drpNumber)
            ->set_data('companyNum',$companyNum)
            ->send(200,'ok');
    }


    //会长信息
    public function prisident_info(Request $request){
        $userId     = $request->input('prisidentId');
        $chapterId  = $request->input('chapterId');

        $prisidentModel     = new PrisidentModel();
        $prisidentInfo      = $prisidentModel->prisident_info($userId);


        $apiData    = new ApiData();
        return $apiData->set_data('prisidentInfo',$prisidentInfo)
            ->send(200,'ok');

    }



}